package com.xinghen.rms;

import org.apache.commons.codec.digest.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author xinghen
 * @ClassName: Constant
 * @Package: com.xinghen.rms
 * @Description 常量
 * @create 2017-12-08 10:54
 */
public class Constant {

    /**
     * 头信息(rms应用名称)
     */
    public static final String HEADER_RMS_APPLICATION_NAME_CODE = "rmsApplicationName";

    /**
     * 头信息(rms认证秘钥)
     */
    public static final String HEADER_RMS_SIGN_CODE = "rmsSign";

    /**
     * 头信息(rms接口编号)
     */
    public static final String HEADER_SERVICE_CODE_CODE = "rmsServiceCode";

    /**
     * 日期格式
     */
    public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH";

    /**
     * http头
     */
    public static final String HTTP = "http://";

    /**
     * https头
     */
    public static final String HTTPS = "https://";

    private Constant() {
    }

    /**
     * 计算sign
     *
     * @param rmsApplicationName
     * @param secret
     * @return
     */
    public static String sign(String rmsApplicationName, String secret) {
        final String split = "_";
        StringBuilder sb = new StringBuilder();
        sb.append(rmsApplicationName).append(split).append(secret).append(split)
                .append(new SimpleDateFormat(DATE_FORMAT).format(new Date()));
        return DigestUtils.md5Hex(sb.toString());
    }

}
